package com.dao;

import java.util.List;

import com.beans.MenuInfo;
import com.jdbc.DBUtil;

public class MenuDao {
	public List<MenuInfo> getMenuList(int parentId){
		List<MenuInfo> menulist = DBUtil.getList("select * from menuInfo where parentId=?", MenuInfo.class, parentId);
		
		for(MenuInfo m:menulist) {
			if(m.getParentId()==0) {
				m.setSubMenuList(getMenuList(m.getId()));
			}
		}
		return menulist;
	}
	
	public List<MenuInfo> getMenuList(int parentId,int roleId){
		List<MenuInfo> menulist = DBUtil.getList("select * from menuInfo where parentId=? and id in (select menuId from rolemenu where roleId=?)", MenuInfo.class, parentId,roleId);
		for(MenuInfo m:menulist) {
			if(m.getParentId()==0) {
				m.setSubMenuList(getMenuList(m.getId(),roleId));
			}
		}
		return menulist;
	}
}
